import java.util.ArrayList;
import java.util.List;

import es.deusto.ingenieria.is.csp.formulation.Variable;

public class Board {
	private CellList section1;
	private CellList section2;
	private CellList section3;
	private ArrayList<Gem> domain;

	public Board() {
		this.section1 = new CellList(4);
		this.section2 = new CellList(4);
		this.section3 = new CellList(4);
		this.domain = new ArrayList<Gem>();

		this.createSections(4);

		this.defineConstraints();
	}
	
	public int getTotalWeight(){
		int count = 0;
		for(int i = 0; i<domain.size(); i++){
			count +=domain.get(i).getWeight();
		}
		return count;
	}

	private void createSections(int size) {

		int j = 1;
		char position = 'A';

		for (int i = 0; i < size; i++) {
			section1.addCell(new Cell(j, (char) (position + i), this.domain));
		}

		j++;
		position = 'A';

		for (int i = 0; i < size; i++) {
			section2.addCell(new Cell(j, (char) (position + i), this.domain));
		}

		j++;
		position = 'A';

		for (int i = 0; i < size; i++) {
			section3.addCell(new Cell(j, (char) (position + i), this.domain));
		}
	}

	public List<Variable<Gem>> getAllCells() {
		List<Variable<Gem>> allCells = new ArrayList<Variable<Gem>>();

		for (Variable<Gem> cell : section1.getCells()) {
			allCells.add(cell);

		}

		for (Variable<Gem> cell : section2.getCells()) {
			allCells.add(cell);
		}

		for (Variable<Gem> cell : section3.getCells()) {
			allCells.add(cell);
		}

		return allCells;
	}

	private void defineConstraints() {
		
	}

	public CellList sectionContains(Variable<Gem> variable) {
		if (section1.contains((Cell) variable)) {
			return section1;
		} else if (section2.contains((Cell) variable)) {
			return section3;
		} else if (section3.contains((Cell) variable)) {
			return section3;
		} else
			return null;
	}

	public void addElementToDomain(Gem element) {
		domain.add(element);
	}

	/*
	 * private List<Variable<Gem>> cellsToVariables(List<Cell> cells) {
	 * List<Variable<Gem>> variables = new ArrayList<Variable<Gem>>();
	 * 
	 * for (Cell cell : cells) { variables.add(cell); }
	 * 
	 * return variables; }
	 */

	public String toString() {

		return null;
	}
}